package com.sp.scmdb.bean;

import java.util.List;

import com.google.common.collect.Lists;

@SuppressWarnings("unchecked")
public class PageBean {

	protected int pageNo = 1;

	protected String pageName;

	protected int pageSize = 15;

	protected int count = 0;

	private List allList = Lists.newArrayList();

	private List list = Lists.newArrayList();

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public int getPageNo() {
		return pageNo == 0 ? 1 : pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		if (pageSize < 1) {
			pageSize = 10;
		}
		this.pageSize = pageSize;
	}

	public int getPageTotal() {
		if (count % pageSize == 0) {
			return count / pageSize;
		} else {
			return count / pageSize + 1;
		}
	}

	public int getCurrentRow() {
		if ((pageSize * (pageNo - 1)) > count) {
			return count;
		}
		if ((pageSize * (pageNo - 1)) < 0) {
			return 0;
		}
		return pageSize * (pageNo - 1);
	}

	public int getLastRow() {
		if (pageSize * pageNo > count) {
			return count;
		}
		return pageSize * pageNo;
	}

	public int getIndex() {
		return pageSize * (pageNo - 1) + 1;
	}

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public List getAllList() {
		return allList;
	}

	public void setAllList(List allList) {
		this.count = allList.size();
		this.allList = allList;
	}

}
